const router=require('express').Router()
const multer=require('multer')
const path=require('path')


const storage = multer.diskStorage({
    destination: function (req, file, cb) {
      cb(null, './public/uploads')
      //图片存储的位置
    },
    filename: function (req, file, cb) {
      cb(null,file.fieldname + '-' +Date.now()+'.'+path.extname(file.originalname))
      //给照片添加后缀名
    }
  })
   
  const upload = multer({ storage: storage })


router.get('/upload',(req,res)=>{
    res.render('upload')
    
})

router.post('/upload',upload.single('img'),(req,res)=>{
    res.send('上传成功')
})
module.exports = router